package ACWing.Greed;
//905. 区间选点    908. 最大不相交区间数量

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

/**
 * @author :chenjie
 * @date :Created 2023/1/13 15:45
 */
public class IntervalSelectionPoint {
    static class Pall{
        int x;
        int y;

        public Pall(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public String toString() {
            return "Pall{" +
                    "x=" + x +
                    ", y=" + y +
                    '}';
        }
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        List<Pall> list=new ArrayList<>();
        while (n-->0){
            int a=sc.nextInt();
            int b=sc.nextInt();
            list.add(new Pall(a,b));
        }
        list.sort(new Comparator<Pall>() {
            @Override
            public int compare(Pall o1, Pall o2) {
                return o1.y-o2.y;
            }
        });
        int sum=1;
        int y=list.get(0).y;
        for (int i = 0; i < list.size(); i++) {//选取最右边的点
            if(list.get(i).y>=y&&list.get(i).x<=y){
                continue;
            }
            sum++;
            y=list.get(i).y;
        }
        System.out.println(sum);
    }
}
